from qturboframe.lib.report.log import logger
from qturboframe.public_ui.base_element import BaseElement


class Tabs(BaseElement):
    '''hui的tab标签类'''

    def select(self, tab_name):
        '''
        选择选项卡

        :Args:
         - tab_name: 选项卡的名称

        :Example:
         - 例: tabs.select('权限分配')
        '''
        tab = self._element.find_element_by_attribute(
            'xpath', './div', 'text:{}'.format(tab_name), timeout=self.timeout)
        tab.secure_click()
        logger.info('打开 {} 选项卡。'.format(tab_name))

    def close(self, tab_name):
        '''
        关闭选项卡

        :Args:
         - tab_name: 选项卡的名称

        :Example:
         - 例: tabs.close('权限分配')
        '''
        tab = self._element.find_element_by_attribute(
            'xpath', './div', 'text:{}'.format(tab_name), timeout=self.timeout)
        tab.move_to()
        tab_i = tab.find_element_by_attribute(
            'xpath', './i[contains(@class, "h-icon-close")]'.format(tab_name),
            timeout=self.timeout)
        tab_i.secure_click()
        logger.info('关闭当前选项卡。')
